package com.demo.service;

import com.demo.dao.StudentDao;
import com.demo.domain.Student;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StudentService {
    //检查用户是否存在的check方法
    public boolean check(String username) throws SQLException {
        return new StudentDao().daoCheck(username);
    }

    //删除用户
    public boolean delete(String id) throws SQLException {
        return new StudentDao().daoDelete(id);
    }
    //检查用户登陆是否成功
    public boolean login(String username, String password) throws SQLException {
        return new StudentDao().daoLogin(username, password);
    }

    //注册
    public Map<String, Object> register(String username, String password, String num, String name, String sex, String birthDay) throws SQLException {
        boolean isHave = check(username);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("isRegister", false);
        if (isHave) {
            map.put("msg", "账号已存在！");
            return map;
        }
        boolean isRegister = new StudentDao().daoRegister(username, password, num, name, sex, birthDay);
        if (isRegister) {
            map.put("isRegister", true);
            map.put("msg", "注册成功！");
            return map;
        } else {
            map.put("msg", "注册失败");
            return map;
        }
    }

    //获取用户列表
    public List<Student> GetList() throws SQLException {
        return new StudentDao().daoGetList();
    }

}
